<template>
    <div>
        充值
        <van-cell-group>
            <van-field v-model="pay" label="充值" placeholder="请输入充值金额" />
            <van-password-input :value="value" info="密码为 6 位数字" :error-info="errorInfo" :focused="showKeyboard"
                @focus="showKeyboard = true" />
            <van-number-keyboard v-model="value" :show="showKeyboard" @blur="showKeyboard = false" />

        </van-cell-group>

        <p><van-button type="info" @click="payurl">充值</van-button></p>
    </div>
</template>

<script>
export default {
    data() {
        return {
            pay: '',
            value: '',
            pwd: '',
            errorInfo: '',
            showKeyboard: true,


        }

    },
    watch: {
        value(value) {
            if (value.length === 6 && value !== this.pwd) {
                this.errorInfo = '密码错误';
            } else {
                this.errorInfo = '';
            }
        },
    },
    methods: {
        payurl() {
            this.axios.get('payurl?pay=' + this.pay + '&userid=' + localStorage.getItem('userid') + '&pwd=' + this.pwd)
            // this.axios.get('payurl?pay=' + this.pay + '&pwd=' + this.pwd)
                .then(res => {
                    console.log(res)
                    window.location.href = res.data.url
                })
        },
        pwds() {//获取当前用户密码
            this.axios.get('pwd?userid=' + localStorage.getItem('userid'))
            // this.axios.get('pwd?userid=8')
                .then(res => {


                    this.pwd = res.data.pwd
                    console.log(this.pwd)

                })
        }

    },
    mounted() {
        this.pwds()
    }

}
</script>

<style>

</style>